<style>

</style>
<template>
    <div>


        <!-- 账户统计 -->
    

              <Spin size="large" fix v-if="spinShow"></Spin>
       
              <!-- 根据条件查询 -->
    <div>
      <el-form :inline="true"  class="demo-form-inline" ref="ruleForm">
        <el-form-item label="银行卡号">
          <el-input v-model="documentNumber" placeholder="请输入单据编号查询"></el-input>
        </el-form-item>
        <el-form-item label="银行名称">
          <el-input v-model="productName" placeholder="请输入商品信息查询"></el-input>
        </el-form-item>
     
        <el-form-item>
          <el-button type="primary" plain   @click="findByPage">查询</el-button>
          <el-button @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </div>


    
        <!-- table展示 -->
       <div>
         <Table
        border
        
        :columns="columns4"
        :data="data1"
     
      >

        <template slot-scope="scope" slot="status">
          <el-tag :type="scope.row.erpState.stateName==='启用'? 'primary':'danger'" >
            {{scope.row.erpState.stateName=='启用'?"启用":"禁用"}}
            </el-tag>
        </template>

      

          <template slot-scope="{ row, index }" slot="action">
          <!-- <Button type="info" size="large"   @click="findSalesOrderBytype(row)">查看流水</Button> -->

            <el-button type="primary" plain   @click="findSalesOrderBytype(row)">查看流水</el-button>
        </template>
      </Table>
    </div>
    <br>


      <!-- 分页 -->
    <div style="float:right">
      <Page
        :total="dataCount"
        :page-size="pageSize"
        @on-change="changepage"
        @on-page-size-change="_nowPageSize"
        show-elevator
      />
    </div>




    
       <!-- 根据银行类型查看 -->
    <Modal v-model="typeFind" title="查看" width="1340">
         <el-button type="primary" plain   @click="exportExcel">导出</el-button>
      <Table class="table"  height="350"  border ref="selection" :columns="columns5" :data="typeList" >
        <template slot-scope="{ row, index }" slot="resName">{{row.erpWarehouseinformation.resName}}</template>

         <template slot-scope="{ row, index }" slot="rid">
           {{row.rid=='1'?'销售':'退款'}}
         </template>
      </Table>
    </Modal>





    </div>
</template>
<script>
import axios from "axios";
import FileSaver from "file-saver";
import XLSX from "xlsx";
export default {
   data() {
      return {
          typeFind:false,


              columns5: [
        {
            title:"#",
            key:"id"
        },
         {
          title: "单据编号",
          key: "documentNumber",
            align:"center",
        },
        {
          title:"交易对象",
          key:"tradingPartners",
            align:"center",
        },
        {
          title: "交易余额",
          key: "transactionAmount",
            align:"center",
        },
      
       
        {
          title:"交易时间",
          key:"documentDate",
            align:"center",
        },
        {
            title:"类型",
            slot:"rid",
            align:"center",

        },
        {
          title:"商品名称:",
          key:"content",
            align:"center",
        }
        
        
       
      ],



            columns4: [
        {
          title: "#",
          key: "id",
            align:"center",
        },
     
        {
          title: "开户银行",
          key: "accountBank",
            align:"center",
        },
        
        {
          title: "银行账号",
          key: "accountNumber",
            align:"center",
        },
        {
            title:"状态",
            slot:"status",
            align:"center",
        },
    
         {title: "operate",
          slot: "action",
            align:"center",
         }

        
      ],
      data1: [],
      spinShow:true,


                   // 分页的条件
      productName: "",
      documentNumber: "",
      begintime: [],


      //分页
        pageSize: 5, //每页显示多少条
      dataCount: 0, //总条数
      pageCurrent: 1, //当前页,

      typeList:[]
      }
      
   },
    created(){
            this.getList();
    },

    methods:{

          // 根据银行类型
    findSalesOrderBytype(row) {
      axios
        .get(
          "http://localhost:8082/Settlementaccount/findRunWaterByType?type=" +
            row.id
        )
        .then(res => {
        //   this.DMNumList = res.data;
          console.log(res.data)
          this.typeList=res.data
        //   this.findSalseDMNumContent = true;
        this.typeFind=true;
        });
    },


         changepage(index) {
       axios
        .post(
          "//localhost:8082/Settlementaccount/getSettlementaccountPage?documentNumber=" +
            this.documentNumber +
            "&productName=" +
            this.productName +
            "&pageSize=" +
            this.pageSize +
            "&pageCurrent=" +
           index
        )
        .then(res => {
          console.log("13123123123213")
          console.log(res.data);
          this.dataCount = res.data.countTotal;
          this.data1 = res.data.list;
         
          //当从数据库获取完毕  关闭加载特效
          this.spinShow=false;
          // this.begintime = "";
        });
    },

    //每页显示的数据条数
    _nowPageSize(index) {
      //实时获取当前需要显示的条数
      this.pageSize = index;
    },

    findByPage(){
       this.spinShow=true;
  axios
        .post(
          "//localhost:8082/Settlementaccount/getSettlementaccountPage?documentNumber=" +
            this.documentNumber +
            "&productName=" +
            this.productName +
            "&pageSize=" +
            this.pageSize +
            "&pageCurrent=" +
            this.pageCurrent
        )
        .then(res => {
          console.log("13123123123213")
          console.log(res.data);
          this.dataCount = res.data.countTotal;
          this.data1 = res.data.list;
         
          //当从数据库获取完毕  关闭加载特效
          this.spinShow=false;
          // this.begintime = "";
        });
    },

          getList(){
         axios
        .post(
          "//localhost:8082/Settlementaccount/getSettlementaccountPage?documentNumber=" +
            this.documentNumber +
            "&productName=" +
            this.productName +
            "&pageSize=" +
            this.pageSize +
            "&pageCurrent=" +
            this.pageCurrent
        )
        .then(res => {
          console.log("13123123123213")
          console.log(res.data);
          this.dataCount = res.data.countTotal;
          this.data1 = res.data.list;
         
          //当从数据库获取完毕  关闭加载特效
          this.spinShow=false;
          // this.begintime = "";
        });
    },














                   // 重置
    resetForm() {
      this.documentNumber = "";
      this.begintime = [];
      this.productName = "";
    },

      // 导出表格所用
    exportExcel() {
      // 设置当前日期
      let time = new Date();
      let year = time.getFullYear();
      let month = time.getMonth() + 1;
      let day = time.getDate();
      let name = year + "" + month + "" + day;
      // console.log(name)
      /* generate workbook object from table */
      //  .table要导出的是哪一个表格
      var wb = XLSX.utils.table_to_book(document.querySelector(".table"));
      /* get binary string as output */
      var wbout = XLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array"
      });
      try {
        //  name+'.xlsx'表示导出的excel表格名字
        FileSaver.saveAs(
          new Blob([wbout], { type: "application/octet-stream" }),
          name + ".xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    }
    }
}
</script>
